package com.limingfeiyu.platform.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.limingfeiyu.common.web.PageTable;
import com.limingfeiyu.common.web.ResultBody;
import org.springframework.web.bind.annotation.RestController;
import com.limingfeiyu.platform.management.service.IHospitalItemService;
import com.limingfeiyu.platform.management.entity.HospitalItem;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 医院_项目 前端控制器 vm
 * </p>
 *
 * @author 黎铭飞羽
 * @since 2024-04-12
 */
@RestController
@RequestMapping("/hospitalItem")
public class HospitalItemController {


    @Autowired
    private IHospitalItemService service;

    // 分页列表
    @PostMapping("/getPageList")
    @ApiOperation(value = "获取分页列表", notes = "pageList")
    @ApiImplicitParam(name = "pageTable", value = "分页表格",
            required = true, type = "ResultBody")
    public ResultBody<Page<HospitalItem>> getPageList(
            @RequestBody PageTable<HospitalItem> pageTable) throws Exception {
        if (pageTable == null) {
            pageTable = new PageTable<>();
            pageTable.setParam(new HospitalItem());
        }
        return ResultBody.ok().data(service.pageList(pageTable));
    }

    // 更新保存
    @PostMapping("/USave")
    @ApiOperation(value = "更新", notes = "ResultBody")
    @ApiImplicitParam(name = "obj", value = "",
            required = true, type = "ResultBody")
    public ResultBody<HospitalItem> USave(@RequestBody HospitalItem obj) {
        if (service.updateById(obj)) {
            return ResultBody.ok().data(obj);
        } else {
            return ResultBody.alert().msg("更新失败！").data(obj);
        }
    }

    // 删除
    @PostMapping("/DSave/{id}")
    @ApiOperation(value = "删除", notes = "ResultBody")
    @ApiImplicitParam(name = "id", value = "",
            required = true, type = "ResultBody")
    public ResultBody DSave(@PathVariable("id") Long id) {
        if (service.removeById(id)) {
            return ResultBody.ok();
        } else {
            return ResultBody.alert().msg("删除失败！").data(new HashMap<String, Object>().put("id", id));
        }
    }

    // 新增
    @PostMapping("/ASave")
    @ApiOperation(value = "新增", notes = "ResultBody")
    @ApiImplicitParam(name = "obj", value = "",
            required = true, type = "ResultBody")
    public ResultBody<HospitalItem> ASave(@RequestBody HospitalItem obj) {
        if (service.save(obj)) {
            return ResultBody.ok().data(obj);
        } else {
            return ResultBody.alert().msg("新增失败！").data(obj);
        }
    }

    // 分页列表
    @PostMapping("/getHospitalItemListByNameOrType")
    @ApiOperation(value = "根据项目类型、项目名称获取医院项目列表", notes = "List")
    @ApiImplicitParam(name = "item", value = "项目对象",
            required = true, type = "ResultBody")
    public ResultBody<List<HospitalItem>> getHospitalItemListByNameOrType(
            @RequestBody HospitalItem item) {
        if (item == null || item.getHospitalId() == null || item.getHospitalId() <= 0) {
            return ResultBody.alert().msg("参数不能为空");
        }
        List<HospitalItem> itemList = service.getHospitalItemListByNameOrType(item);
        return ResultBody.ok().data(itemList);
    }
}

